part of '../repository.dart';

class _PurchasedItemGettingSuccessfulResponseDto {
  const _PurchasedItemGettingSuccessfulResponseDto._internal({
    required this.appStorePurchasedItemDtos,
    required this.googlePlayPurchasedItemDtos,
    required this.webPurchasedItemDtos,
  });

  final BuiltList<_AppStorePurchasedItemDto> appStorePurchasedItemDtos;
  final BuiltList<_GooglePlayPurchasedItemDto> googlePlayPurchasedItemDtos;
  final BuiltList<_WebPurchasedItemDto> webPurchasedItemDtos;

  factory _PurchasedItemGettingSuccessfulResponseDto.fromJson(Map<String, dynamic> json) {
    final appStorePurchasedItemData = json['app_store_purchased_items'] as List;

    final appStorePurchasedItemMaps = List.castFrom<dynamic, Map>(appStorePurchasedItemData);

    final appStorePurchasedItemDtos = appStorePurchasedItemMaps.map((appStorePurchasedItemMap) {
      final appStorePurchasedItemJson =
          Map.castFrom<dynamic, dynamic, String, dynamic>(appStorePurchasedItemMap);

      return _AppStorePurchasedItemDtoFactory().fromJson(appStorePurchasedItemJson);
    }).toBuiltList();

    final googlePlayPurchasedItemData = json['google_play_purchased_items'] as List;

    final googlePlayPurchasedItemMaps = List.castFrom<dynamic, Map>(googlePlayPurchasedItemData);

    final googlePlayPurchasedItemDtos =
        googlePlayPurchasedItemMaps.map((googlePlayPurchasedItemMap) {
      final googlePlayPurchasedItemJson =
          Map.castFrom<dynamic, dynamic, String, dynamic>(googlePlayPurchasedItemMap);

      return _GooglePlayPurchasedItemDtoFactory().fromJson(googlePlayPurchasedItemJson);
    }).toBuiltList();

    final webPurchasedItemData = json['web_purchased_items'] as List;

    final webPurchasedItemMaps = List.castFrom<dynamic, Map>(webPurchasedItemData);

    final webPurchasedItemDtos = webPurchasedItemMaps.map((webPurchasedItemMap) {
      final webPurchasedItemJson =
          Map.castFrom<dynamic, dynamic, String, dynamic>(webPurchasedItemMap);

      return _WebPurchasedItemDtoFactory().fromJson(webPurchasedItemJson);
    }).toBuiltList();

    return _PurchasedItemGettingSuccessfulResponseDto._internal(
      appStorePurchasedItemDtos: appStorePurchasedItemDtos,
      googlePlayPurchasedItemDtos: googlePlayPurchasedItemDtos,
      webPurchasedItemDtos: webPurchasedItemDtos,
    );
  }
}
